package com.nuance.assignment.fileInfo.shared;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Data Transfer Object for response.
 * 
 * This is a generic response object for any payload, and all the controllers in
 * the application should return only this object or it's subclasses. Even in
 * the case of exception, this object should be populated accordingly and
 * returned.
 * 
 * This is the class that will be used to convert response information into Json
 * format. Thus any Json marshaling related annotations, if required, should be
 * put on this class.
 * 
 * @author parag
 *
 */
public class ResponseDTO<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * Denotes wether is request has been successfully served or not
	 */
	private boolean success = true;
	/**
	 * Accumulated messages while serving the request
	 */
	private final List<String> messages = new ArrayList<>();
	/**
	 * Actual payload to be returned to client, can be null
	 */
	private T payload;

	public ResponseDTO() {

	}

	public ResponseDTO(T payload) {
		this.payload = payload;
	}

	public void setPayload(T payload) {
		this.payload = payload;
	}

	public T getPayload() {
		return payload;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public boolean isSuccess() {
		return success;
	}

	public List<String> getMessages() {
		return messages;
	}

	@Override
	public String toString() {
		return "ResponseDTO [success=" + success + ", messages=" + messages
				+ ", payload=" + payload + "]";
	}

}
